package com.imooc.api;

import com.imooc.api.intercept.JWTCurrentUserInterceptor;
import com.imooc.api.intercept.SMSInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @version 1.0
 * @Author Mr.Yang
 * @Date 2024-08-05 19:49
 * @question: 拦截器注册器
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 注册进来短信拦截器
     * @return
     */
    @Bean
    public SMSInterceptor smsInterceptor() {
        return new SMSInterceptor();
    }

    @Bean
    public JWTCurrentUserInterceptor jwtCurrentUserInterceptor() {
        return new JWTCurrentUserInterceptor();
    }

    /**
     * 注册短信拦截器用于拦截的地址
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(smsInterceptor())
                .addPathPatterns("/passport/getSMSCode");

        //所有方法当中都会进行
        registry.addInterceptor(jwtCurrentUserInterceptor())
                .addPathPatterns("/**");
    }

}
